using System;
using System.Collections.Generic;
using System.Text;

namespace LogFileViewer
{
    public enum MessageTypes
    {
        FATAL, ERROR, WARN, DEBUG, INFO, UNDEFINED
    }

    public class MessageType
    {
        public static int Length()
        {
            Array elements = Enum.GetValues(typeof(MessageTypes));
            if (elements != null)
            {
                return elements.Length - 1; // -1 because UNDEFINED
            }
            return 0;
        }

        public static string[] StringArray()
        {
            string[] types = Enum.GetNames(typeof(MessageTypes));
            return types;
        }

        public static Array TypesArray()
        {
            Array types = Enum.GetValues(typeof(MessageTypes));
            return types;
        }

        public static MessageTypes MessageTypeAt(int i)
        {
            Array types = Enum.GetValues(typeof(MessageTypes));
            return (MessageTypes)types.GetValue(i);
        }

        public static MessageTypes GetMessageType(string msgtype)
        {
            string[] msgTypes = StringArray();
            for (int i = 0; i < msgTypes.Length; i++)
            {
                if (msgtype.Equals(msgTypes[i],StringComparison.CurrentCultureIgnoreCase))
                {
                    return MessageTypeAt(i);
                }
            }
            return MessageTypes.UNDEFINED;
        }
    }
}
